package com.github.admin.edu.security.jwt.server.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;

/**
 * Create by IntelliJ IDEA
 * 用户：王建
 * 日期：2018-8-1
 */
@Entity
@Table(name = "T_SYS_USER")
public class TSysUser implements Serializable {

    private String id;
    private String userid;
    private String lasttime;
    private String locked;
    private String loginip;
    private Integer loginnum;
    private Integer orgid;
    private String password;
    private Integer state;
    private String name;
    private Integer yhsf;

    private TSysOrginzation orginzation;

    private String orgname;

    @Id
    @Column(name = "id")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Basic
    @Column(name = "userid")
    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    @Basic
    @Column(name = "lasttime")
    public String getLasttime() {
        return lasttime;
    }

    public void setLasttime(String lasttime) {
        this.lasttime = lasttime;
    }

    @Basic
    @Column(name = "locked")
    public String getLocked() {
        return locked;
    }

    public void setLocked(String locked) {
        this.locked = locked;
    }

    @Basic
    @Column(name = "loginip")
    public String getLoginip() {
        return loginip;
    }

    public void setLoginip(String loginip) {
        this.loginip = loginip;
    }

    @Basic
    @Column(name = "loginnum")
    public Integer getLoginnum() {
        return loginnum;
    }

    public void setLoginnum(Integer loginnum) {
        this.loginnum = loginnum;
    }

    @Basic
    @Column(name = "orgid")
    public Integer getOrgid() {
        return orgid;
    }

    public void setOrgid(Integer orgid) {
        this.orgid = orgid;
    }

    @Basic
    @Column(name = "password")
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Basic
    @Column(name = "state")
    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    @Basic
    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Column(name = "yhsf")
    public Integer getYhsf() {
        return yhsf;
    }

    public void setYhsf(Integer yhsf) {
        this.yhsf = yhsf;
    }

    @ManyToOne(cascade = {CascadeType.MERGE,CascadeType.REFRESH})
    @JoinColumn(name = "orgid",referencedColumnName = "id",updatable = false,insertable = false)
    public TSysOrginzation getOrginzation() {
        return orginzation;
    }

    public void setOrginzation(TSysOrginzation orginzation) {
        if(null!=orginzation){
            this.orgname=orginzation.getName();
        }
        this.orginzation = orginzation;
    }


    @Transient
    public String getOrgname() {
        return orgname;
    }

    public void setOrgname(String orgname) {
        this.orgname = orgname;
    }



    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TSysUser tSysUser = (TSysUser) o;
        return Objects.equals(id, tSysUser.id) &&
                Objects.equals(userid, tSysUser.userid) &&
                Objects.equals(lasttime, tSysUser.lasttime) &&
                Objects.equals(locked, tSysUser.locked) &&
                Objects.equals(loginip, tSysUser.loginip) &&
                Objects.equals(loginnum, tSysUser.loginnum) &&
                Objects.equals(orgid, tSysUser.orgid) &&
                Objects.equals(password, tSysUser.password) &&
                Objects.equals(state, tSysUser.state) &&
                Objects.equals(name, tSysUser.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, userid, lasttime, locked, loginip, loginnum, orgid, password, state, name);
    }
}
